home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Level 0 Macintosh 29Sep94 / Debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  5.9 KB  |  199 lines  |  [TEXT/KAHL]

  1. /* Debug.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    System Dependency Library for Building Portable Software               */
  5. /*    Macintosh Version                                                      */
  6. /*    Written by Thomas R. Lawrence, 1993 - 1994.                            */
  7. /*                                                                           */
  8. /*    This file is Public Domain; it may be used for any purpose whatsoever  */
  9. /*    without restriction.                                                   */
  10. /*                                                                           */
  11. /*    This package is distributed in the hope that it will be useful,        */
  12. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  13. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   */
  14. /*                                                                           */
  15. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  16. /*                                                                           */
  17. /*****************************************************************************/
  18.  
  19. #include "MiscInfo.h"
  20. #include "Definitions.h"
  21. #include "Debug.h"
  22. #include "Audit.h"
  23.  
  24. #ifdef THINK_C
  25.     #pragma options(pack_enums)
  26. #endif
  27. #include <Quickdraw.h>
  28. #include <Windows.h>
  29. #include <Memory.h>
  30. #include <Controls.h>
  31. #include <OSEvents.h>
  32. #include <SegLoad.h>
  33. #include <TextEdit.h>
  34. #ifdef THINK_C
  35.     #pragma options(!pack_enums)
  36. #endif
  37.  
  38.  
  39. /* debugging function, use it to present message */
  40. #define MAINWINDOWCOORDS  70,40,512-70,342-120
  41. #define TEXTBOXCOORDS  8,24,512-70-70-8,342-120-40-8
  42. #define RESUMEBUTTONCOORDS  8,342-120-40-8-20,96+8,342-120-40-8
  43. #define QUITBUTTONCOORDS  120,342-120-40-8-20,96+128,342-120-40-8
  44.  
  45. /* if AbortFlag == True, then it is impossible to recover from error and */
  46. /* the application must be forced to quit */
  47. /* 'Message' is a C-String [null terminated] */
  48. #define EmergencyCacheSize (8192)
  49.  
  50.  
  51. EXECUTE(static MyBoolean    Inited = False;)
  52.  
  53. static Handle                            Emergency = NIL;
  54.  
  55.  
  56. /* turn off any weird options */
  57. #pragma options(!profile)
  58. #pragma options(!mc68020)
  59.  
  60.  
  61. void                            PRERR(int AbortFlag, char* Message)
  62.     {
  63.         WindowRecord        ErrorWindow;
  64.         Rect                        Bounds;
  65.         Rect                        TextRect;
  66.         EventRecord            MyEvent;
  67.         WindowPtr                WhichWindow;
  68.         ControlHandle        ResumeButton;
  69.         ControlHandle        QuitButton;
  70.         ControlHandle        WhichOne;
  71.         long                        NumChars;
  72.         short                        CommandKeyDown;
  73.  
  74.         if (Emergency != NIL)
  75.             {
  76.                 DisposHandle(Emergency);
  77.                 Emergency = NIL;
  78.             }
  79.         APRINT(("+PRERR: '%t'",Message));
  80.         #if ALWAYSRESUME
  81.             AbortFlag = AllowResume; /* while we're debugging, we can resume */
  82.         #endif
  83.         SetRect(&Bounds,MAINWINDOWCOORDS);
  84.         NewWindow(&ErrorWindow,&Bounds,"\p",True,1,(GrafPort*)-1,False,0);
  85.         SelectWindow((WindowPtr)&ErrorWindow);  /* force it to be on top */
  86.         SetRect(&Bounds,RESUMEBUTTONCOORDS);
  87.         ResumeButton = NewControl((WindowPtr)&ErrorWindow,&Bounds,
  88.             "\pResume",True,0,0,0,pushButProc,0);
  89.         SetRect(&Bounds,QUITBUTTONCOORDS);
  90.         QuitButton = NewControl((WindowPtr)&ErrorWindow,&Bounds,
  91.             "\pQuit",True,0,0,0,pushButProc,0);
  92.         if (AbortFlag == ForceAbort)
  93.             {
  94.                 HiliteControl(ResumeButton,255);  /* make it inactive */
  95.             }
  96.         FlushEvents(everyEvent,0);
  97.         while (True)
  98.             {
  99.                 GetNextEvent(everyEvent,&MyEvent);
  100.                 CommandKeyDown = ((MyEvent.modifiers & cmdKey) != 0);
  101.                 switch (MyEvent.what)
  102.                     {
  103.                         case mouseDown:
  104.                             GlobalToLocal(&MyEvent.where);
  105.                             if (FindControl(MyEvent.where,(WindowPtr)&ErrorWindow,&WhichOne) != 0)
  106.                                 {
  107.                                     if (WhichOne != NIL)
  108.                                         {
  109.                                             if (WhichOne == QuitButton)
  110.                                                 {
  111.                                                     if (TrackControl(QuitButton,MyEvent.where,NIL) != 0)
  112.                                                         {
  113.                                                             APRINT(("-PRERR: abort"));
  114.                                                             ENDAUDIT();
  115.                                                             if (CommandKeyDown)
  116.                                                                 {
  117.                                                                     goto SkipBrk1Point;
  118.                                                                 }
  119.                                                             #if DEBUGGER_PRESENT
  120.                                                                 #if DEBUG
  121.                                                                     Debugger(); /* break point */
  122.                                                                 #endif
  123.                                                             #endif
  124.                                                          SkipBrk1Point:
  125.                                                             ExitToShell(); /* exit from the program */
  126.                                                         }
  127.                                                 }
  128.                                             if (WhichOne == ResumeButton)
  129.                                                 {
  130.                                                     if (TrackControl(ResumeButton,MyEvent.where,NIL) != 0)
  131.                                                         {
  132.                                                             goto ExitPoint;
  133.                                                         }
  134.                                                 }
  135.                                         }
  136.                                 }
  137.                             break;
  138.                         case updateEvt:
  139.                             BeginUpdate((WindowPtr)&ErrorWindow);
  140.                             SetPort(&ErrorWindow.port);
  141.                             TextFont(0);  /* system font */
  142.                             TextFace(0);  /* normal */
  143.                             TextMode(srcOr);
  144.                             TextSize(12);  /* 12 point */
  145.                             SpaceExtra(0);  /* no extra space */
  146.                             MoveTo(8,16);
  147.                             DrawString("\pAn Internal Program Error Occurred:");
  148.                             SetRect(&TextRect,TEXTBOXCOORDS);
  149.                             /* finding length of message string */
  150.                             NumChars = 0;
  151.                             while ( ((char*)Message)[NumChars] != 0)
  152.                                 {
  153.                                     NumChars += 1;
  154.                                 }
  155.                             TextBox(Message,NumChars,&TextRect,teJustLeft);
  156.                             DrawControls((WindowPtr)&ErrorWindow);
  157.                             EndUpdate((WindowPtr)&ErrorWindow);
  158.                             break;
  159.                         default:
  160.                             break;
  161.                     }
  162.             }
  163.      ExitPoint:
  164.         CloseWindow((WindowPtr)&ErrorWindow);
  165.         APRINT(("-PRERR"));
  166.         GetNextEvent(activMask,&MyEvent); /* clear activate event for underlying window */
  167.         if (CommandKeyDown)
  168.             {
  169.                 goto SkipBrk2Point;
  170.             }
  171.         Emergency = NewHandle(EmergencyCacheSize);
  172.         #if DEBUGGER_PRESENT
  173.             #if DEBUG
  174.                 Debugger(); /* break point */
  175.             #endif
  176.         #endif
  177.      SkipBrk2Point:
  178.         return;
  179.     }
  180.  
  181.  
  182. void                            Eep_InitPRERR(void)
  183.     {
  184.         ERROR(Inited,PRERR(ForceAbort,"InitPRERR called more than once."));
  185.         Emergency = NewHandle(EmergencyCacheSize);
  186.         EXECUTE(Inited = True;)
  187.     }
  188.  
  189.  
  190. void                            Eep_ShutdownPRERR(void)
  191.     {
  192.         ERROR(!Inited,PRERR(ForceAbort,"ShutdownPRERR:  not initialized"));
  193.         if (Emergency != NIL)
  194.             {
  195.                 DisposHandle(Emergency);
  196.                 Emergency = NIL;
  197.             }
  198.     }
  199.